<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <style>
        body {
            background: url(/images/index.jpg);
            /* 调整背景图大小 */
            background-size: cover;
            background-position: center;
        }
        #login{
            width: 350px;
            height: 400px;
            background: #c5e6f8aa;
            margin: 250px auto;
            border-radius: 15px;
        }
        .logform{
            width: 100%;
            height: 50px;
            background: #c5e6ffaa;
            float: left;
            border-radius: 10px 10px 0 0;
            text-align: center;
            line-height: 50px;
        }
        .logleft{
            width: 30%;
            height: 40px;
            border-radius: 10px 10px 0 0;
            text-align: center;
            line-height: 40px;
            float: left;
            clear: right;
        }
        .logright{
            width: 70%;
            height: 40px;
            text-align: left;
            line-height: 40px;
            float: left;
            clear: right;
        }
    </style>
    <!-- 引入 jQuery 库 -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <div id="login">
        <form action="">
            <div class="logform">用户登录</div>
            <div class="logleft">用户名</div><div class="logright"><input id="name" name="name"></div>
            <div class="logleft">密码</div><div class="logright"><input id="password" name="password" type="password"></div>
            <div class="logleft">确认密码</div><div class="logright"><input id="password2" name="password2" type="password"></div>
            <div class="logleft">性别</div>
            <div class="logright">
                <input id="male" name="sex" type="radio" value="男" checked="checked">男
                <input id="female" name="sex" type="radio" value="女">女
            </div>
            <div class="logleft">籍贯</div><div class="logright">
                <select name="" id="native">
                    <option value="">请选择</option>
                    <option value="江苏">江苏</option>
                    <option value="浙江">浙江</option>
                    <option value="安徽">安徽</option>
                </select>
            </div>
            <div class="logleft">爱好</div><div class="logright">
                <input type="checkbox" name="hobby" value="上网">上网
                <input type="checkbox" name="hobby" value="学习" checked="checked">学习
                <input type="checkbox" name="hobby" value="唱歌">唱歌
            </div>
            <div class="logleft"></div><div class="logright">
                <input type="button" value="注册" onclick="mydata()"/>
                <input type="reset" value="重置"/>
            </div>
        </form>
    </div>
    <script>
        function mydata(){
            var love="";
            var name=$('#name').val();
            var password=$('#password').val();
            var password2=$('#password2').val();
            var sex=$("input[name='sex']:checked").val();
            var nativeplace = $('#native').val();
            var hobby = $("input[name='hobby']");
            for(i in hobby){
                if(hobby[i].checked){
                    love+=hobby[i].value
                }
            }
            if(name == ""){
                alert("用户名不能为空")
            }
            if(password == password2){
                alert("用户名: "+ name +" 密码: "+ password + "密码2: " + password2 + " 性别: " + sex + "籍贯: " + nativeplace + "爱好: " + love)
                $.post("/goregister",{name:name,password:password},function (result){
                    if(result == true){
                        alert("注册成功");
                        window.location.href ="/login";
                    }
                    else{
                        alert("注册失败");
                    }
                })
            }
            else{
                alert("两次密码不一致！")
            }

        }
    </script>
</body>
</html>